//-----------------------------------------------------------------------------
//
//  <No description>
//
//  Microsoft Zenith Project
//  Copyright ©2001,2002,2003,2004 Microsoft Corporation
//  One Microsoft Way, Redmond, Washington 98052-6399 U.S.A.
//  All rights reserved.
//  MICROSOFT CONFIDENTIAL
//
//-----------------------------------------------------------------------------

#ifndef _HAG_I2C__GPIO_H_1
#define _HAG_I2C__GPIO_H_1   1

//////////////////////////////////////////////////////////////////////////////
// HAG_I2C_GPIO_Driver
//
struct HAG_I2C_GPIO_Driver
{
    enum GPIO_NAMES {
        I2C0=96,
		I2C1=97,
		I2C2=98,
		I2C3=99,
		I2C4=100,
		I2C5=101,
		I2C6=102,
		I2C7=103
    };

    //--//

	static const unsigned c_FirstIo = I2C0;
	static const unsigned c_MaxPins = 8;
	static const UINT32   c_InitDone = 0xff66532b;
	static const UINT8    c_Gpio_Attributes[c_MaxPins];

    //--//


	struct PIN_ISR_DESCRIPTOR
    {
        GPIO_INTERRUPT_SERVICE_ROUTINE code;
        void*                          data;
		int							   mode;
    } m_IsrCallbacks[c_MaxPins];

	UINT32             		m_PinReservationInfo[c_MaxPins];
    UINT32			   		m_IOMap;
	UINT32			   		m_IOMap_Old;
	UINT32   				m_InitDone;

	I2C_HAL_XACTION	   		m_i2cXactionRead;
	I2C_HAL_XACTION	   		m_i2cXactionWrite;
	I2C_HAL_XACTION_UNIT	m_i2cXactionUnitRead;
	I2C_HAL_XACTION_UNIT	*m_i2cXactionUnitReadRef[1];
	I2C_HAL_XACTION_UNIT	m_i2cXactionUnitWrite;
	I2C_HAL_XACTION_UNIT	*m_i2cXactionUnitWriteRef[1];

	I2C_WORD				m_OutputData[2];
	I2C_WORD				m_txbuf[2],m_rxbuf[2];

	int 					m_pending;
	int 					m_txactions;
	
	BOOL					m_warmstart;

	//--//

    static BOOL Initialize  ();
    static BOOL Uninitialize();
    static UINT32 Attributes( GPIO_PIN Pin );
    static void DisablePin( GPIO_PIN Pin, GPIO_RESISTOR ResistorState, UINT32 direction, GPIO_ALT_MODE AltFunction );
    static void EnableOutputPin( GPIO_PIN Pin, BOOL InitialState );
    static BOOL EnableInputPin( GPIO_PIN Pin, BOOL GlitchFilterEnable, GPIO_INTERRUPT_SERVICE_ROUTINE ISR, void* ISR_Param, GPIO_INT_EDGE IntEdge, GPIO_RESISTOR ResistorState );
    static BOOL GetPinState( GPIO_PIN Pin );
    static void SetPinState( GPIO_PIN Pin, BOOL PinState );
    static void SetResistor( GPIO_PIN Pin, GPIO_RESISTOR ResistorState );
    static BOOL PinIsBusy( GPIO_PIN Pin );
    static BOOL ReservePin( GPIO_PIN Pin, BOOL fReserve );
    static UINT32 GetDebounce();
    static BOOL SetDebounce( INT64 debounceTimeMilliseconds );
    static void GetPinsMap( UINT8* pins, size_t size );
	static void I2C_IS_UP();

private:

    static void GPIOISRVector( GPIO_PIN Pin, BOOL PinState, void* Param );
	static void I2CCallback(void* Param );
	static void I2CCallbackTx(void* Param );
	static void PC8575_Read_Inputs();
	static void PC8575_Write_Outputs();

};

extern HAG_I2C_GPIO_Driver g_HAG_I2C_GPIO_Driver;
//
// HAG_I2C_GPIO_Driver
//////////////////////////////////////////////////////////////////////////////
#endif
